
import JSEncrypt from './jsencrypt.min'
import Request from '@/utils/request'

const getRSAPublicKey = ()=>{ // 获取rsa公钥
    return new Promise((resolve,reject)=>{
        Request.get('/rsa/publicKey')
        .then(res=>{
            resolve(res.data) 
        })
    })
}

export const encodeRSA = async(data) =>{ // rsa加密
    return new Promise(async(resolve,reject)=>{
        const res = await getRSAPublicKey()
        const key = res.data
        const encryptTool = new JSEncrypt()
        encryptTool.setPublicKey(key)
        resolve(encryptTool.encrypt(data))
    })
    
}